package com.xiaohei.EE_IBATIC_Demo.dao.ibatis;

import java.util.List;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.xiaohei.EE_IBATIC_Demo.dao.IUserDao;
import com.xiaohei.EE_IBATIC_Demo.model.Department;
import com.xiaohei.EE_IBATIC_Demo.model.PageQuery;
import com.xiaohei.EE_IBATIC_Demo.model.User;

public class UserDaoImpl extends SqlMapDaoTemplate implements IUserDao{
	public UserDaoImpl(DaoManager manager) {
		super(manager);
	}
	public boolean registUser(User u ){
		boolean b = this.checkIfUserExist(u.getUser_name());
		if(b==false){
			this.insert("registUser", u);
		}
		return b;
	}
	public boolean addUser(User u) {
		boolean b = this.checkIfUserExist(u.getUser_name());
		if(b==true){
			this.update("addUser", u);
		}
		return b;
	}
	public Integer deleteUser(Integer id) {
		
		return this.delete("deleteUserById", id);
	}
	public Integer updateUser(User u) {
		Integer id = (Integer)this.update("updateUser", u);
		return id;
	}
	public List<User> findAllUser(){
		List<User> as = this.queryForList("findAllUser",User.class);
		return as;
	}
	public List<User> findAllUserByPage(PageQuery p) {
		List<User> as = this.queryForList("findAllUserByPage",p);
		return as;
	}
	public Integer getPageCount(){
		Integer i = (Integer) this.queryForObject("getUserPageCount",java.lang.Integer.class );
		return i;
	}
	public boolean checkIfUserExist(String uName){
		boolean b = false;
		Integer i = (Integer) this.queryForObject("checkIfUserExist",uName);
		if(i!=0){
			b=true;
		}
		return b;
	}

}
